package org.travel.app.controller;
import com.github.pagehelper.PageInfo;
import org.springframework.http.HttpStatus;
import org.travel.app.common.vo.ResultVO;
import org.travel.app.common.vo.PageVo;

/**
 * @author wangl
 * @date 2024/10/12
 */
public class BaseController<T> {

    public <T> ResultVO<T> success(PageInfo pageInfo)  {
        PageVo result = new PageVo();
        result.setCode(HttpStatus.OK.value());
        result.setData((T) pageInfo.getList());
        result.setCount(pageInfo.getTotal());
        return result;
    }

    public ResultVO success() {
        ResultVO result = new ResultVO<>();
        result.setData("success");
        result.setCode(HttpStatus.OK.value());
        return result;
    }

    public ResultVO success(T data) {
        ResultVO result = new ResultVO<>();
        result.setCode(HttpStatus.OK.value());
        result.setData(data);
        return result;
    }
    
    public ResultVO error(int code,String msg) {
        ResultVO result = new ResultVO<>();
        result.setCode(code);
        result.setMessage(msg);
        return result;
    }

}